package com.example.jt_web.controller;

import com.example.jt_web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.http.HttpRequest;

@Controller
public class UserController {


    @Autowired
    UserService userService;

    @RequestMapping(name = "login",method = RequestMethod.POST)
    public void login(String username, String password, HttpServletRequest request){
        //先从cookie中找到ticket
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie: cookies ) {
            //如果有，拿着ticket去登录
            if (cookie.getName().equals("jt_cookie")){
                String ticket = cookie.getValue();

            }else {
                //如果没有，直接登录
                userService.userLogin(username,password);
            }
        }

        //如果超过30分钟，ticket失效，那么再让用户使用userlogin，并保存cookie
    }



    public void checkTicket(){

    }
}
